//
//  CCBottomLineTableViewCell.m
//  SmartHomeViews
//
//  Created by haimen_ios_imac on 2017/6/20.
//  Copyright © 2017年 深圳海曼科技有限公司. All rights reserved.
//

#import "CCBottomLineTableViewCell.h"

@implementation CCBottomLineTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        _bottomLineLFPadding = 10.0f;
        _bottomLineHeight = .5f;
        _bottomLineColor = [UIColor lightGrayColor];
        _textFont = 15.0f;
        _detailTextFont = 13.0f;
        _textColor = RGBA_COLOR(0x333333FF);
        _detailTextColor = RGBA_COLOR(0x666666FF);
        
        self.selectionStyle = UITableViewCellSelectionStyleBlue;
        self.textLabel.font = [UIFont systemFontOfSize:_textFont];
        self.detailTextLabel.font = [UIFont systemFontOfSize:_detailTextFont];
        self.textLabel.textColor = _textColor;
        self.detailTextLabel.textColor = _detailTextColor;
    }
    return self;
}

#pragma mark setter
- (void)setBottomLineColor:(UIColor *)bottomLineColor
{
    _bottomLineColor = bottomLineColor;
    [self setNeedsDisplay];
}

- (void)setBottomLineHeight:(CGFloat)bottomLineHeight
{
    _bottomLineHeight = bottomLineHeight;
    [self setNeedsDisplay];
}

- (void)setBottomLineLFPadding:(CGFloat)bottomLineLFPadding
{
    _bottomLineLFPadding = bottomLineLFPadding;
    [self setNeedsDisplay];
}

- (void)setTextFont:(CGFloat)textFont
{
    _textFont = textFont;
    self.textLabel.font = [UIFont systemFontOfSize:_textFont];
}

- (void)setDetailTextFont:(CGFloat)detailTextFont
{
    _detailTextFont = detailTextFont;
    self.detailTextLabel.font = [UIFont systemFontOfSize:_textFont];
}

- (void)setTextColor:(UIColor *)textColor
{
    _textColor = textColor;
    self.textLabel.textColor = _textColor;
}

- (void)setDetailTextColor:(UIColor *)detailTextColor
{
    _detailTextColor = detailTextColor;
    self.detailTextLabel.textColor = _detailTextColor;
}

#pragma mark Drawer
- (void)drawRect:(CGRect)rect
{
    CGFloat width = rect.size.width;
    CGFloat height = rect.size.height;
    
    CGContextRef ref = UIGraphicsGetCurrentContext();
    CGContextMoveToPoint(ref, _bottomLineLFPadding, height-_bottomLineHeight);
    CGContextAddLineToPoint(ref, width-_bottomLineLFPadding, height-_bottomLineHeight);
    
    CGContextSetLineWidth(ref, _bottomLineHeight);
    CGContextSetStrokeColorWithColor(ref, _bottomLineColor.CGColor);
    CGContextStrokePath(ref);
}

@end
